package com.lzl.soaware;

import com.lzl.soaware.config.SoawareProperties;
import com.lzl.soaware.db.config.DataSourceConfig;
import com.lzl.soaware.frame.aop.SoawareAspect;
import com.lzl.soaware.scheduled.RetrySchedulered;
import com.lzl.soaware.service.ClearService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
@ComponentScan
@EnableScheduling
@EnableConfigurationProperties(SoawareProperties.class)
public class SoawareAutoConfiguration {

    @Autowired
    private SoawareProperties properties;

    @Bean
    @ConditionalOnMissingBean
    public ClearService clearService() {
        ClearService service = new ClearService();
        service.setName(properties.getName());
        return  service;
    }

    @Bean
    public SoawareAspect soawareAspect() {
        return new SoawareAspect();
    }

    @Bean
    public DataSourceConfig dataSourceConfig() {
        return new DataSourceConfig();
    }

    @Bean
    @ConditionalOnExpression("${soaware.retry.enable:true}")
    public RetrySchedulered retrySchedulered() {
        return new RetrySchedulered();
    }
}
